package com.bw.lyc.mvp.model.entity;

import com.bw.lyc.mvp.base.model.BaseEntity;
import com.bw.lyc.util.LogUtils;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

/**
 * [
 * {\"medias\":
 * [{\"media_type\":0,\"media_id\":20,\"media_url\":\"string\"}],
 * \"news_type\":0,\"news_author\":\"string\",\"news_value\":\"string\",
 * \"news_title\":\"string\",\"news_url\":\"string\",\"news_time\":0,
 * \"author_id\":0,\"channel_id\":0,\"news_id\":37},
 * {\"medias\":[{\"media_type\":0,\"media_id\":21,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻1\",\"news_title\":\"测试1\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":38},{\"medias\":[{\"media_type\":0,\"media_id\":22,\"media_url\":\"imgs1.jpeg\"},{\"media_type\":0,\"media_id\":23,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻2\",\"news_title\":\"测试2\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":39},{\"medias\":[{\"media_type\":0,\"media_id\":24,\"media_url\":\"imgs1.jpeg\"},{\"media_type\":0,\"media_id\":25,\"media_url\":\"imgs1.jpeg\"},{\"media_type\":0,\"media_id\":26,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻3\",\"news_title\":\"测试3\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":40},{\"medias\":[{\"media_type\":0,\"media_id\":27,\"media_url\":\"imgs1.jpeg\"},{\"media_type\":0,\"media_id\":28,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻4\",\"news_title\":\"测试4\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":41},{\"medias\":[{\"media_type\":0,\"media_id\":29,\"media_url\":\"imgs1.jpeg\"},{\"media_type\":0,\"media_id\":30,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻5\",\"news_title\":\"测试5\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":42},{\"medias\":[{\"media_type\":0,\"media_id\":31,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻6\",\"news_title\":\"测试6\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":43},{\"medias\":[{\"media_type\":0,\"media_id\":32,\"media_url\":\"imgs1.jpeg\"},{\"media_type\":0,\"media_id\":33,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻7\",\"news_title\":\"测试7\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":44},{\"medias\":[{\"media_type\":0,\"media_id\":34,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻8\",\"news_title\":\"测试8\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":45},{\"medias\":[{\"media_type\":0,\"media_id\":35,\"media_url\":\"imgs1.jpeg\"}],\"news_type\":0,\"news_author\":\"编辑1\",\"news_value\":\"测试新闻9\",\"news_title\":\"测试9\",\"news_url\":\"http:\/\/118.195.161.134:8066\/index.html#\/\",\"news_time\":1622029278,\"author_id\":1,\"channel_id\":1,\"news_id\":46}]
 * */

public class RecommendEntity extends BaseEntity {
    public String values;

    public List<Values>getValues(){
        if (values == null)
            return null;
        List<Values> list = new ArrayList<>();
        try {
            JSONArray jay = new JSONArray(values);
            for (int i = 0;i < jay.length();i ++){
                String str = jay.getString(i);
                LogUtils.e("RecommendEntity:values:"+str);
                Values values = new Gson().fromJson(str,Values.class);
                list.add(values);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return list;
    }

    public static class Values{
        public int news_type;
        public String news_author;
        public String news_value;
        public String news_title;
        public String news_url;
        public long news_time;
        public long author_id;
        public long channel_id;
        public long news_id;
        public List<MediaValues> medias;

        public List<MediaValues>getMedias(){
//            if (medias == null)
//                return null;
//            List<MediaValues> list = new ArrayList<>();
//            try {
//                JSONArray jay = new JSONArray(medias);
//                for (int i =0;i < jay.length();i ++){
//                    String media = jay.getString(i);
//                    MediaValues mediaValues = new Gson().fromJson(media,MediaValues.class);
//                    list.add(mediaValues);
//                }
//            } catch (JSONException e) {
//                e.printStackTrace();
//            }
            return medias;
        }

    }

    public static class MediaValues{
        public int media_type;
        public long media_id;
        public String media_url;
    }


}
